package org.streets.eis.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.streets.database.SQLConnection;
import org.streets.database.annotations.NestedFetch;


@Entity
@Table(name="eis_employee")
public class Employee {
		
	@Id
	public String id;
	
	@Column
	public String name;

	@Column(name="user_id")
	public String userId;
	
	@Column(name="organ_id")
	public String organId;

	@Column(name="pos_id")
	public String posId;
	

	@NestedFetch("select * from eis_user where user_id = :userId")
	public User user;

	@NestedFetch("select * from eis_position where id = :posId")
	public Position position;
	
		
	public Employee() {
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public User getUser() {
		return user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}
	
	public Organization getOrgan(SQLConnection connection) {
		return connection.unique(Organization.class, organId);
	}
	
	public void setOrgan(Organization organ) {
		organId = organ.getId();
	}
	
	public Position getPosition(SQLConnection connection) {
		return connection.unique(Position.class, posId);
	}
	
	public void setPosition(Position position) {
		posId = position.getId();
	}
}
